import React,{Component} from 'react';

//高阶组件：接收一个组件返回一个新组件
function IsLogin(Com){
    return class extends Component{
        state = {
            status:false  //登录的状态
        }
        
        componentDidMount(){
            let token = localStorage.getItem('token') || '';

            if(token){
                this.setState({
                    status:true
                })
            }else{
                this.props.history.push('/login')
            }
        }
        render(){
            let {status} = this.state;
            return (
                status ? <Com {...this.props}></Com> : <></>
            )
        }
    }
}

export default IsLogin